<html>
<head>
    <meta charset="UTF-8">
    netty websocket 时间服务器
</head>
<br>
<body>
<br>
<script type="text/javascript">
    var socket;
    if(!window.WebSocket){
        window.WebSocket = window.MozWebSocket;
    }
    if(window.WebSocket){
        var  socket = new WebSocket("ws://localhost:8080/websocket");
        socket.onmessage = function(event){
            var ta = document.getElementById('responseText');
            ta.value="";
            ta.value = event.data
        };
        socket.onopen = function(event){
            var ta = document.getElementById('responseText');
            ta.value = '';
            ta.value = "打开websocket服务正常，浏览器支持websocket!";
        };
        socket.onclose = function(event){
            var ta = document.getElementById('responseText');
            ta.value = '';
            ta.value = "websocket关闭!";
        };
    }else{
        alert("抱歉，您的浏览器不支持WebSocket 协议！");
    }
    function send(message){
        if(!window.WebSocket){
            return;
        }
        if(socket.readyState == window.WebSocket.OPEN){
            socket.send(message);
        }else{
            alert("WebSocket 还没有建立连接！")
        }
    }
</script>
<form onsubmit="return false;">
    <input type="text" name="message" vaule="Netty权威指南 WebSocket协议开发"/>
    <br><br>
    <input type="button" value="发送 WebSocket 请求消息" onclick="send(this.form.message.value)">
    <hr color="blue"/>
    <h3>服务端返回的应答消息</h3>
    <textarea id="responseText" style="width:500px;height:300px;"></textarea>
</form>
</body>
</html>
